package com.situ.meetingRoom.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Arrays;

@WebFilter(filterName = "LogFilter" , urlPatterns = "/*")
public class LogFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        //打印日志
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        //访问路径
        System.out.println(req.getRequestURI());
        //传递的参数
        for (String name : req.getParameterMap().keySet()){
            System.out.println(name + "-" + Arrays.toString(req.getParameterMap().get(name)));
        }
        //请求头
        System.out.println(req.getHeader("user-agent"));
        //客户端的IP
        System.out.println(req.getRemoteHost());
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
